package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysProject;
import com.ruoyi.system.domain.MaterialEntity;
import com.ruoyi.system.domain.MaterialReportEntity;
import com.ruoyi.system.domain.TProjectAim;
import com.ruoyi.system.mapper.MaterialMapper;
import com.ruoyi.system.mapper.MaterialReportMapper;
import com.ruoyi.system.mapper.TProjectAimMapper;
import com.ruoyi.system.service.MaterialReportService;
import com.ruoyi.system.service.MaterialService;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MaterialReportServiceImpl extends ServiceImpl<MaterialReportMapper, MaterialReportEntity> implements MaterialReportService {

    @Autowired
    private MaterialReportMapper materialReportMapper;


    public boolean upsertMaterialLogReport(MaterialReportEntity materialReportEntity) {

        // 判断是否存在

        if (materialReportEntity.getMaterialLogId()  != null && !materialReportEntity.getMaterialLogId().equals("0")) {
            var existWrapper = new LambdaQueryWrapper<MaterialReportEntity>()
                    .eq(MaterialReportEntity::getMaterialLogId,materialReportEntity.getMaterialLogId()).eq(MaterialReportEntity::getDelFlag,0);
            var existEntry = this.getOne(existWrapper);

            if (existEntry != null) {
                // 设置 id
                materialReportEntity.setId(existEntry.getId());
            }
        }

        saveOrUpdate(materialReportEntity); //

        return true;
    }



    public List<MaterialReportEntity> getMaterialLogReports(List<String> materialLogIds) {


        var existWrapper = new LambdaQueryWrapper<MaterialReportEntity>()
                .in(MaterialReportEntity::getMaterialLogId, materialLogIds).eq(MaterialReportEntity::getDelFlag,0);


        return materialReportMapper.selectList(existWrapper);
    }
}
